//
//  HomeNomalCellTableViewCell.m
//  陶瓷
//
//  Created by 郭天龙 on 15/7/6.
//  Copyright (c) 2015年 王戈. All rights reserved.
//

#import "HomeNomalCellTableViewCell.h"
#import "UIImageView+WebCache.h"

@interface HomeNomalCellTableViewCell ()

@property (nonatomic, strong) HomeCellModel *model;

@end

@implementation HomeNomalCellTableViewCell

- (void)awakeFromNib {
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (void)setModelWithDic:(NSDictionary *)dic
{
    self.model = [[HomeCellModel alloc] init];
    self.model.Height = [dic objectForKey:@"Height"];
    self.model.name = [dic objectForKey:@"Name"];
    self.model.adverArr = [dic objectForKey:@"Advertisements"];
    self.model.idnum = [dic objectForKey:@"Id"];
    
    CGFloat width = kDefaultWindowWidth/[self.model.adverArr count];
    int i = 0;
    for (NSDictionary *dic in self.model.adverArr) {
        //        UIWebView *imageview = [[UIWebView alloc] initWithFrame:CGRectMake(i*width, 0, width, self.model.Height.floatValue/2)];
        UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(i*width, 0, width, self.model.Height.floatValue/2)];
        [imageview sd_setImageWithURL:[dic objectForKey:@"ImageUrl"] placeholderImage:nil];
        imageview.layer.borderWidth = 0.25;
        imageview.layer.borderColor =  [UIColor lightGrayColor].CGColor;
//        imageview.layer.borderColor = TCColor(51, 51, 51, 1).CGColor;
        //        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[dic objectForKey:@"ImageUrl"]]];
        //        [imageview loadRequest:request];
        //        imageview.scalesPageToFit = YES;
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"" forState:UIControlStateNormal];
        [button setBackgroundColor:[UIColor clearColor]];
        button.frame = imageview.frame;
        [button addTarget:self action:@selector(clickAdverView:) forControlEvents:UIControlEventTouchUpInside];
        button.tag = i;
        i++;
        [self.contentView addSubview:imageview];
        [self.contentView addSubview:button];
    }
    //    self.layer.borderWidth = 1;
    //    self.layer.borderColor = [UIColor lightGrayColor].CGColor;
    
}

-(void)clickAdverView:(UIButton *)sender
{
    if ([self.delegate respondsToSelector:@selector(didADInfoVC:)]) {
        [self.delegate didADInfoVC:[self.model.adverArr objectAtIndex:sender.tag]];
    }
}

@end
